<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:02:30
 * @LastEditTime: 2020-02-28 11:25:38
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/fastclick.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <style>
        .box {
            padding: 0 50px;
            display: flex;
            flex-direction: column;
        }

        .title {
            width: 100%;
            text-align: center;
            font-size: 18px;
            font-weight: 700;
            color: #e6c678;
        }

        .form {
            width: 100%;
        }

        .table {
            padding-bottom: 20px;
            flex: 1;
        }

        .table table tr td {
            text-align: center;
        }

        .van-field {
            width: 33.33%;
            float: left;
        }

        .van-cell {
            background-color: transparent;
        }

        .van-field__control {
            border-bottom: 2px solid #e6c678;
        }

        .van-cell::after {
            border-bottom: 0;
        }

        input {
            background: none;
            outline: none;
            border: none;
        }

        .bottomBtns .bottomBtn_L {
            flex: 1;
            padding-right: 10px;
        }

        .bottomBtns .bottomBtn_R {
            width: 100%;
            display: flex;
        }

        .bottomBtns .bottomBtn_R .van-button {
            width: 80%;
            margin: auto;
        }

        .top {
            width: 100%;
            padding-top: 5px;
            display: flex;
        }

        .topLeft {
            width: 50%;
            padding-left: 5px;
        }

        .top .van-button {
            margin-top: 10px;
            margin-left: 5px;
            padding: 10px 20px;
        }

        .scanPop {
            width: 160px;
            height: 180px;
            text-align: center;
            background-color: transparent;
            margin: 0;
            padding: 0;
        }

        .van-icon-enlarge {
            font-size: 150px;
            color: #e6c678;
            margin: 0;
            padding: 0;
        }

        .inputClass {
            opacity: 0;
            width: 150px;
        }

        .scanLine {
            position: absolute;
            z-index: 2;
            width: 66%;
            height: 2px;
            transform: translateX(25%);
            background-color: #e6c678;
            animation: scanLineMove 2s infinite;
        }

        .newClass {
            color: red;
        }

        @keyframes scanLineMove {
            from {
                top: 30px;
            }

            to {
                top: 120px;
            }
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box" id="box">
            <!-- <div class="top">
                <div class="topLeft">
                    <van-button class="back" color="linear-gradient(#fffeaa, #c07d39)" type="primary" size="small"
                        @click="historyBack()">返回
                    </van-button>
                </div>
            </div> -->
            <div class="form">
                <van-field v-model="formData.EquipmentName" label="故障机台：" placeholder="请选择故障机台" readonly
                    @click="openBaseScreen('机台')">
                </van-field>
                <van-field v-model="formData.FaultTypeName" label="故障类型：" placeholder="请选择故障类型" readonly
                    @click="openBaseScreen('故障类型')">
                </van-field>
                <van-field v-model="formData.FaultName" label="故障原因：" placeholder="请选择故障原因" readonly
                    @click="reasonShow = true">
                </van-field>
                <!-- <van-field v-model="formData.Comment" label="备注：" placeholder="请输入备注">
                </van-field> -->
                <van-field v-model="formData.DecUserName" label="申报人：" placeholder="请输入申报人"></van-field>
            </div>
            <van-field style="width: 100%;" v-model="formData.GZContent" label="处理内容：" placeholder="请输入处理内容"
                @click="handlerPageSize">
            </van-field>
            <van-field style="width: 100%;" v-model="formData.Result" label="处理结果：" placeholder="请输入处理结果"></van-field>
            <van-field style="width: 100%;" v-model="formData.nm" label="处理人：" readonly placeholder="请选择处理人"
                @click="handlerNm">
            </van-field>
            <van-field style="width: 100%;" v-model="formData.FRemarks" label="处理备注：" placeholder="请输入处理备注">
            </van-field>

            <div class="bottomBtns">
                <!-- <div class="bottomBtn_L">
                </div> -->
                <div class="bottomBtn_R">
                    <van-button color="linear-gradient(#fffeaa, #c07d39)" type="primary" block @click="submit">
                        完 &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp 成
                    </van-button>
                </div>
            </div>

            <van-popup v-model="scanShow" class="scanPop">
                <div class="scanLine"></div>
                <van-icon name="enlarge"></van-icon>
                <input id="autoInput" inputmode="none" class="inputClass" type="number" v-model="inputCode" ref="input" autofocus
                    @keyup.enter="inputFocus()">
            </van-popup>
            <van-action-sheet v-model="reasonShow" :actions="reasonActions" @select="onSelectReason"></van-action-sheet>
        </div>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {

        api.addEventListener({
            name: 'selectRow'
        }, function (ret, err) {
            var type = ret.value.type;
            var row = ret.value.row;
            if (type == '机台') {
                vm.formData.EquipmentName = row.EquipmentName;
                vm.formData.EquipmentID = row.EquipmentID;
            } else if (type == '故障类型') {
                vm.formData.FaultTypeName = row.name
                vm.formData.FaultTypeID = row.FaultTypeID

                APP.ajax('getZSFault', { FaultTypeID: row.FaultTypeID }, function (res) {
                    console.log('res', JSON.stringify(res))
                    vm.reasonActions = res.ds
                })
            }
        })

        vm = new Vue({
            el: '#app',
            data: {
                formData: {
                    EquipmentName: '',
                    EquipmentID: '',
                    FaultTypeName: '',
                    FaultTypeID: '',
                    FaultName: '',
                    Comment: '',
                    DecUserName: '',
                    Declarer: '',
                    GZContent: '',
                    Result: '',
                    nm: '',
                    nmID: '',
                    FRemarks: ''
                },
                reasonShow: false,
                reasonActions: [],
                scanShow: false,
                inputCode: ''
            },
            created: function () {
                var that = this;
                if (window.localStorage.getItem('clientHeight') != 752) {
                    document.getElementById('app').style.zoom = 0
                } else {
                    document.getElementById('app').style.zoom = 1.5
                }
                console.log('pageParam', JSON.stringify(api.pageParam))
                if (api.pageParam.historyData) {
                    that.formData.EquipmentName = api.pageParam.historyData.EquipmentName + api.pageParam.historyData.EquipmentCode
                    that.formData.EquipmentID = api.pageParam.historyData.EquipmentID
                    that.formData.FaultTypeName = api.pageParam.historyData.FaultTypeName
                    that.formData.FaultTypeID = api.pageParam.historyData.FaultTypeID
                    that.formData.FaultName = api.pageParam.historyData.FaultName
                    that.formData.Comment = api.pageParam.historyData.Comment
                    that.formData.DecUserName = api.pageParam.historyData.DecUserName
                    that.formData.Declarer = api.pageParam.historyData.Declarer

                    APP.ajax('getZSFault', { FaultTypeID: that.formData.FaultTypeID }, function (res) {
                        console.log('res', JSON.stringify(res))
                        that.reasonActions = res.ds
                    })
                }
            },
            methods: {
                handlerPageSize() {
                    var that = this
                    let height = document.documentElement.clientHeight
                    window.onresize = () => { // 在页面大小发生变化时调用
                        // 把获取到的高度赋值给根div
                        document.getElementById('box').style.height = height + 'px'
                    }
                },
                historyBack() {
                    api.closeFrame()
                },
                handlerNm() {
                    var that = this
                    that.scanShow = true
                    setInterval(() => {
                        that.$refs.input.focus()
                        that.$refs.input.setAttribute('readonly', 'readonly');
                        setTimeout(function () {
                            that.$refs.input.removeAttribute('readonly');
                        }, 500);
                    }, 1500)
                },
                inputFocus() {
                    var that = this
                    vm.$toast(that.inputCode);
                    APP.ajax('ZS_CardLogin', { P_Card: that.inputCode }, function (res) {
                        if (res.ds[0].status == 200) {
                            that.formData.nm = res.ds[0].Name
                            that.formData.nmID = res.ds[0].pin

                            var obj = {
                                FilePath: '',
                                FilePath3: '',
                                FilePath4: '',
                                FaultDocID: api.pageParam.historyData.FaultDocID,
                                FRemarks: that.formData.FRemarks,
                                Name: that.formData.nm,
                                Result: that.formData.Result,
                                FilePath2: '',
                                FaultTypeID: that.formData.FaultTypeID,
                                pin: that.formData.nmID,
                                FaultName: that.formData.FaultName,
                                GZContent: that.formData.GZContent
                            }
                            console.log('obj', JSON.stringify(obj))
                            APP.ajax('ZS_UpDateFaultDoc', obj, function (res) {
                                console.log('res', JSON.stringify(res))
                                vm.$toast('提交成功！')
                                api.sendEvent({
                                    name: 'refreshBroke'
                                })
                                api.sendEvent({
                                    name: 'refreshBrowser',
                                    extra: {
                                        breadData: {
                                            name: '故障明细',
                                            url: 'deviceBrokeCall',
                                            ZS_FunctionID: 0,
                                            click: true
                                        }
                                    }
                                })
                                api.closeFrame()
                            })
                            that.scanShow = false
                        } else {
                            vm.$toast(res.ds[0].msg);
                        }
                        that.inputCode = ''
                    })
                },
                openBaseScreen(str) {
                    var that = this
                    var obj;
                    if (str == '机台') {
                        obj = {
                            allowClear: false,
                            showSearch: true,
                            searchKey: '',
                            serverSearch: false,
                            searchBy: ['EquipmentName'],
                            isPaging: false,
                            type: str,
                            cmd: 'getZSEquipment',
                            param: {
                            }
                        }
                    } else if (str == '故障类型') {
                        obj = {
                            allowClear: false,
                            showSearch: true,
                            searchKey: '',
                            serverSearch: false,
                            searchBy: ['name'],
                            isPaging: false,
                            type: str,
                            cmd: 'getZSFaultType',
                            param: {
                            }
                        }
                    }

                    api.openWin({
                        name: 'baseScreen',
                        url: 'common/baseScreen.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: obj
                    })
                },
                onSelectReason(val) {
                    var that = this
                    that.formData.FaultName = val.name
                    that.reasonShow = false
                },
                submit() {
                    var that = this
                    that.scanShow = true
                }
            }
        })
    };
</script>

</html>